package com.dubbo.consumer.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.dubbo.provider.pojo.TestDb;
import com.dubbo.provider.pojo.TestDb2;
import com.dubbo.provider.service.ITestDb2Service;
import com.dubbo.provider.service.ITestDbService;
import io.seata.core.context.RootContext;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ConsumerController {

    @Reference // 引入远程接口
     ITestDbService testDbService;

    @Reference // 引入远程接口
     ITestDb2Service testDb2Service;

    @GetMapping("/hello")
    @GlobalTransactional
    public void test() {
        System.out.println("分布式事务===XID =:" + RootContext.getXID());
        TestDb testDb = new TestDb();
        testDb.setId(1L);
        testDb.setMoney(27);

        testDbService.updateById(testDb);


        TestDb2 testDb2 = new TestDb2();
        testDb2.setId(1L);
        testDb2.setMoney(30);
        testDb2Service.updateById(testDb2);

        int i = 20;
        int a = i/0;
    }

}
